home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / UI / WinUtilM.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  5.2 KB  |  210 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        WinUtilM.cpp
  3.  
  4.     Contains:    Utilities to manipulate Mac windows
  5.  
  6.     Owned by:    Richard Rodseth
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      11/12/96    TJ        The new API no-longer uses STRICT_WINDOWS.
  13.          <8>      9/8/95    TÇ        1281096 FB2:Many constants in ODTypesB
  14.                                     without kOD prefix!
  15.          <7>     6/28/95    RR        1242642 BB Mostly ref counting. Add
  16.                                     WindowLink::ShouldRemove
  17.          <6>     6/22/95    RR        #1245283 Undoable frame deletion
  18.                                     #1209427 Changed private api between
  19.                                     iterator and iteratee. Allow deletion while
  20.                                     iterating. Added fRemove flag to WindowLink
  21.          <5>     5/26/95    RR        #1251403: Multithreading naming support
  22.          <4>     5/25/95    jpa        Removed GetNextWindow, which is now in
  23.                                     Toolbox <Windows.h> [1241078, 1253324]
  24.          <3>     4/14/95    TÇ        With RR & CG: #1194507 DR/BB:title bar of a
  25.                                     draft window doesn't reveal it is a draft
  26.                                     or which draft it is.  Add
  27.                                     AcquireDraftNumFromDraft
  28.          <2>     9/29/94    RA        1189812: Mods for 68K build.
  29.          <1>     6/16/94    RR        first checked in
  30.  
  31.     To Do:
  32.     In Progress:
  33.         
  34. */
  35.  
  36. #ifndef _WINUTILM_
  37. #include "WinUtilM.h" 
  38. #endif
  39.  
  40. #ifndef __LOWMEM__
  41. #include <LowMem.h> // For WindowList global
  42. #endif
  43.  
  44. #ifndef SOM_ODDraft_xh
  45. #include <Draft.xh>
  46. #endif
  47.  
  48. #ifndef SOM_ODDocument_xh
  49. #include <Document.xh>
  50. #endif
  51.  
  52.  
  53. // New Window API uses a new "WindowRef" type as an opaque window type. So that we can compile
  54. // with or without the new Windows.h, define WindowRef if it's not already defined:      --jpa
  55. //#ifndef STRICT_WINDOWS
  56. //#define WindowRef WindowPeek
  57. //#endif
  58.  
  59.  
  60. WindowPtr GetWindowList()
  61. {
  62.     return (WindowPtr)LMGetWindowList();
  63. }
  64.  
  65. void SetWindowList(WindowPtr theWindow)
  66. {
  67.     LMSetWindowList((WindowRef)theWindow); /* Adkins -- changed from WindowPeek to WindowRef */
  68. }
  69.  
  70. void SetNextWindow(WindowPtr theWindow, WindowPtr nextWindow)
  71. {
  72.     ((WindowRecord*) theWindow)->nextWindow = (WindowPeek) nextWindow;
  73. }
  74.  
  75. ODBoolean GetWindowVisible(WindowPtr theWindow)
  76. {
  77.     return (((WindowRecord*) theWindow)->visible ? kODTrue : kODFalse);
  78. }
  79.  
  80. ODBoolean GetWindowHilite(WindowPtr theWindow)
  81. {
  82.     return (((WindowRecord*) theWindow)->hilited ? kODTrue : kODFalse);
  83. }
  84.  
  85. void SetWindowHilite(WindowPtr theWindow, ODBoolean windowHilite)
  86. {
  87.     ((WindowRecord*) theWindow)->hilited = windowHilite;
  88. }
  89.  
  90. RgnHandle GetStructureRegion(WindowPtr theWindow)
  91. {
  92.     return ((WindowRecord*) theWindow)->strucRgn;
  93. }
  94.  
  95. RgnHandle GetContentRegion(WindowPtr theWindow)
  96. {
  97.     return ((WindowRecord*) theWindow)->contRgn;
  98. }
  99.  
  100. ODULong GetDraftNumFromDraft(Environment* ev, ODDraft* draft)
  101. {
  102.   ODULong draftNumber = 0;
  103.   ODDocument* document = draft->GetDocument(ev);
  104.  
  105.   if (document->Exists(ev, 0, draft, kODPosFirstAbove))
  106.   {
  107.      ODDraft* aDraft = document->AcquireBaseDraft(ev, kODDPReadOnly);
  108.      draftNumber = 1;
  109.      while (!ODObjectsAreEqual(ev, aDraft, draft))
  110.      {
  111.        ++draftNumber;
  112.        aDraft = document->AcquireDraft(ev, kODDPReadOnly, 0, aDraft, 
  113.                                        kODPosFirstAbove, kODTrue);
  114.      } 
  115.      ODReleaseObject(ev, aDraft);
  116.   }
  117.   return draftNumber;
  118. }
  119.  
  120. //=====================================================================================
  121. // WindowLink
  122. //=====================================================================================
  123.  
  124. //-------------------------------------------------------------------------------------
  125. // WindowLink::WindowLink
  126. //
  127. // Description
  128. //-------------------------------------------------------------------------------------
  129.  
  130. WindowLink::WindowLink(ODID windowID, ODWindow* window)
  131. {
  132.     fID = windowID;
  133.     fWindow = window;
  134.     fRemove = kODFalse;
  135. }
  136.  
  137. ODBoolean WindowLink::ShouldRemove()
  138. {
  139.     if (fRemove)
  140.         return kODTrue; // Separate line for debugging purposes
  141.     else
  142.         return kODFalse;
  143. }
  144.  
  145. //=====================================================================================
  146. // WindowListIterator - iterates over the Window Manager window list. Iterating from
  147. // back to front using Last/Previous obviously results in several scans of the list,
  148. // as it's a singly-linked list
  149. //=====================================================================================
  150.  
  151.                                                 
  152.  
  153. WindowListIterator::WindowListIterator()
  154. {
  155.     fCurrentWindow = kODNULL;
  156. }  
  157.  
  158. WindowListIterator::~WindowListIterator()
  159. {
  160. }  
  161.  
  162. WindowPtr WindowListIterator::First()
  163. {    
  164.     fCurrentWindow = FrontWindow();
  165.     return fCurrentWindow;
  166. }
  167.  
  168. WindowPtr WindowListIterator::Next()
  169. {
  170.     if (fCurrentWindow)
  171.         fCurrentWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
  172.     return fCurrentWindow;
  173. }
  174.  
  175. WindowPtr WindowListIterator::Last()
  176. {    
  177.     fCurrentWindow = FrontWindow();
  178.     if (fCurrentWindow)
  179.     {
  180.         WindowPtr nextWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
  181.         while (nextWindow)
  182.         {
  183.             fCurrentWindow = nextWindow;
  184.             nextWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
  185.         }
  186.     }
  187.     return fCurrentWindow;
  188. }
  189.  
  190. WindowPtr WindowListIterator::Previous()
  191. {
  192.     WindowPtr savedCurrent = fCurrentWindow;
  193.     
  194.     fCurrentWindow = FrontWindow();
  195.                 
  196.     while (fCurrentWindow && ( (WindowPtr) (((WindowPeek)fCurrentWindow)->nextWindow) != savedCurrent))
  197.     {
  198.             fCurrentWindow = (WindowPtr) (((WindowPeek) fCurrentWindow)->nextWindow);
  199.     }
  200.     return fCurrentWindow;
  201. }
  202.  
  203. ODBoolean WindowListIterator::IsNotComplete()
  204. {
  205.     return (fCurrentWindow != kODNULL);
  206. }  
  207.  
  208.  
  209.  
  210.